package com.api.service.impl;

import cn.hutool.core.util.StrUtil;
import com.api.common.page.PageData;
import com.api.common.service.impl.BaseServiceImpl;
import com.api.entity.Artcle;
import com.api.entity.User;
import com.api.entity.dto.ArtcleDTO;
import com.api.entity.dto.UserDTO;
import com.api.mapper.ArtcleMapper;
import com.api.service.IArtcleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 文章表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-08-16
 */
@Service
public class ArtcleServiceImpl extends BaseServiceImpl<ArtcleMapper, Artcle> implements IArtcleService {
    @Override
    public PageData<ArtcleDTO> page(Map<String, Object> params) {
        IPage<Artcle> page = baseDao.selectPage(getPage(params,  false),
                getWrapper(params)
        );
        return getPageData(page, ArtcleDTO.class);
    }
    private QueryWrapper<Artcle> getWrapper(Map<String, Object> params) {
        String title = (String) params.get("title");
        QueryWrapper<Artcle> wrapper = new QueryWrapper<>();
        wrapper.like(StrUtil.isNotBlank(title), "title", title);
        return wrapper;
    }

}
